<template>
  <div>
    <el-cascader
      :value="value"
      :options="options"
      :props="defaultProp"
      @change="handleChange"
    />
  </div>
</template>

<script>
import { getDepartment } from '@/api/department'
import { arr2tree } from '@/utils'

export default {
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      defaultProp: {
        value: 'id',
        label: 'name'
      },
      options: []
    }
  },
  created() {
    this.loadDepartment()
  },
  methods: {
    async loadDepartment() {
      const res = await getDepartment()
      // console.log('部门名称',res.data)
      const options = arr2tree(res.data, 0)
      this.options = options
    },
    handleChange(value) {
      console.log(value)
      const id = value[value.length - 1]
      this.$emit('input', id)
    }
  }
}
</script>

<style>
</style>
